package main;

import command.Command;
import command.CommandFactory;
import command.CommandFactory.CommandCode;

/**
 * Hello world!
 *
 */
public class App {
	private static App instance = null;

	private App() {
	}

	public static synchronized App getInstance() {
		if (instance == null) {
			return new App();
		}
		return instance;
	}

	public static void main(String[] args) {
		Console.println("You can use the \"HELP\" for command usage. Have fun!");
		while (true) {
			String cmd = Console.askInput("cmd");
			CommandCode cmdcode = null;

			try {
				cmdcode = CommandCode.valueOf(cmd.toUpperCase());
			} catch (Exception e) {
				Console.println("你输入了一个不合法的命令！请使用HELP查看使用帮助");
				continue;
			}

			CommandFactory factory = new CommandFactory();
			Command command = factory.buildCommand(cmdcode);
			command.execute();
		}
	}
}
